﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication2
{
    public class DataBaseProxy
    {
        private static string ConnectionString = null;

        public static void SetConnectionString(string newConnectionString)
        {
            if (ConnectionString == null)
            {
                ConnectionString = newConnectionString;
            }
        }


        public System.Data.DataSet LoadDataSet(string query)
        {
            var connection = new System.Data.SqlClient.SqlConnection();
            connection.ConnectionString = ConnectionString;
            var sqlCommand = connection.CreateCommand();
            sqlCommand.CommandText = query;

            var dataset = new System.Data.DataSet();
            var adapter = new System.Data.SqlClient.SqlDataAdapter();
            adapter.SelectCommand = sqlCommand;
            adapter.Fill(dataset);

            return dataset;
        }

        public System.Data.DataSet LoadDataSet(System.Data.SqlClient.SqlCommand cmd)
        {
            var connection = new System.Data.SqlClient.SqlConnection();
            connection.ConnectionString = ConnectionString;
            cmd.Connection = connection;

            var dataset = new System.Data.DataSet();
            var adapter = new System.Data.SqlClient.SqlDataAdapter();
            adapter.SelectCommand = cmd;
            adapter.Fill(dataset);

            return dataset;
        }



    }
}